package com.huluobo.a2202mvvm_im_douyindemo.adapter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.huluobo.a2202mvvm_im_douyindemo.R;
import com.huluobo.a2202mvvm_im_douyindemo.bean.VideoListBeanResult;
import com.huluobo.a2202mvvm_im_douyindemo.utils.ImageLoader;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

/**
 * Created by LC on 2024/5/6.
 */
public class VideoAdapter extends BaseQuickAdapter<VideoListBeanResult.VideoListBean, BaseViewHolder> {
    public VideoAdapter(@Nullable List<VideoListBeanResult.VideoListBean> data) {
        super(R.layout.item_video, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoListBeanResult.VideoListBean videoListBean) {
        StandardGSYVideoPlayer player = baseViewHolder.getView(R.id.item_video_gsyPlayer);
        player.getBackButton().setVisibility(View.GONE);
        //设置播放地址
        player.setUp(videoListBean.getVideopath(), true, "");

        //左下区域赋值
        //地址
        baseViewHolder.setText(R.id.item_video_address_tv, videoListBean.getAddress());
        //用户名作者名
        baseViewHolder.setText(R.id.item_video_authname_tv, videoListBean.getAuthname());
        //描述
        baseViewHolder.setText(R.id.item_video_caption_tv, videoListBean.getCaption());
        //原创(跑马灯)
        baseViewHolder.setText(R.id.item_video_pao_tv, videoListBean.getAuthname() + "的原创作品");

        //右下方区域赋值
        //头像
        ImageLoader.getInstance().loadCircleImage(getContext(), videoListBean.getHeadpath(),
                baseViewHolder.getView(R.id.item_video_header_iv));
        //关注状态,0代表未关注,现实+号,1代表关注,隐藏_号
        if (videoListBean.getGuanzhu() == 0) {
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.VISIBLE);
        } else {
            baseViewHolder.getView(R.id.item_video_add_iv).setVisibility(View.GONE);
        }
        //点赞状态,0代表未点赞(白心),1代表点赞(红心)
        if (videoListBean.getDianzan() == 0) {
            baseViewHolder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuan);
        } else {
            baseViewHolder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuanred);
        }
        //点赞数量
        int likeCount = videoListBean.getLike_count();
        baseViewHolder.setText(R.id.item_video_like_count_tv, likeCount < 10000 ? String.valueOf(likeCount) :
                likeCount / 10000 + "W");
        //评论数量
        baseViewHolder.setText(R.id.item_video_comment_count_tv, "5.5W");
        //收藏数量
        baseViewHolder.setText(R.id.item_video_follow_count_tv, "3.2W");
        //分享数量
        baseViewHolder.setText(R.id.item_video_share_count_tv, "2.2W");
        //碟片动画
        ImageLoader.getInstance().loadCircleImage(getContext(), videoListBean.getHeadpath(),
                baseViewHolder.getView(R.id.item_video_music_iv));

        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(baseViewHolder.getView(R.id.item_video_music_iv),
                "Rotation", 0, 360);
        objectAnimator.setDuration(3000);
        objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
        objectAnimator.setInterpolator(new LinearInterpolator());
        objectAnimator.start();

    }
}
